// logo.cpp : Implementation of WinMain


// Note: Proxy/Stub Information
//      To build a separate proxy/stub DLL, 
//      run nmake -f logops.mk in the project directory.

#include "resource.h"
#include "LogoWnd.h"
#include "logolib/logo_lib.h"
#include "WndReg.h"
#include "resource.h"

CModule _Module;
CWndReg reg(100);

BOOL CheckModelessDlgMessages(CWndReg* reg, MSG* msg);

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpCmd, int )
{
   _Module.Init( hInstance );
   BOOL ret = _Module.InitCommonControls();

   CLogoWnd wnd;
   RECT rect = {100, 100, 1000, 800};
   wnd.CreateLogoWnd(&rect);
   
   if (lpCmd && strlen(lpCmd)) {
      char fn[_MAX_PATH];
      /* Remove the quotation marks*/
      strncpy (fn, lpCmd+1, _MAX_PATH);
      size_t last = strlen(fn) -1;
      fn[last] = '\0';
      wnd.ReadFile(fn);
   }
   HACCEL hAccel = LoadAccelerators(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDR_MAINMENU));

   MSG msg;
   while( GetMessage( &msg, NULL, 0, 0 ) ) {
      if (CheckModelessDlgMessages(&reg, &msg)) {
           continue;
      }
      if (!TranslateAccelerator(wnd.m_hWnd, hAccel, &msg)) {
         TranslateMessage( &msg );
         DispatchMessage( &msg );
      }
   }
   DeleteFile(LOGO_TMP_FILE);
   return msg.wParam;
}

BOOL CheckModelessDlgMessages(CWndReg* reg, MSG* msg)
{
    UINT i = 0;
    for (i = 0; i < reg->m_uCount; i++) {
        if (::IsDialogMessage(reg->m_pArray[i], msg)) {
            return TRUE;
        }
    }
    return FALSE;
}

